new Vue({
    el: '.container-fluid',
    data: {
        loginBy: {
            userId: localStorage.getItem("userId"),
            email: true,
            username: false,
            phone: false
        }
    },
    created: function () {
        $("span.mr-2.d-none.d-lg-inline.text-gray-600.small").text(localStorage.getItem("nickName"));
        axios.get("http://localhost:8080//usersettings/userSettingsInfo", {
            params: {
                "userId": localStorage.getItem("userId")
            }
        }).then(response => {
            for (let userSetting of response.data.data) {

                if (userSetting.preferenceKey == "email") {
                    this.loginBy.email = true;
                }
                if (userSetting.preferenceKey == "username") {
                    this.loginBy.username = true;
                }
                if (userSetting.preferenceKey == "phone") {
                    this.loginBy.phone = true;
                }
            }
        })
    },
    methods: {
        saveUserSettings: function () {
            axios.get("http://localhost:8080/usersettings/saveUserSettings", {
                params: {
                    userId: localStorage.getItem("userId"),
                    email: this.loginBy.email,
                    username: this.loginBy.username,
                    phone: this.loginBy.phone
                }
            }).then(response => {
                if (response.data.code != 200) {
                    alert(response.data.message)
                }
                location.href = "settings.html"
            })
        }
    }
})